

package org.example.design.designmode.proxy.jdkproxy.house;

import org.example.design.designmode.proxy.jdkproxy.house.HouseService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class HouseProxy implements  InvocationHandler{

   private HouseService target;

   public HouseService getInstance(HouseService ho){
       this.target = ho;
       Class ck = ho.getClass();
       return (HouseService)Proxy.newProxyInstance(ck.getClassLoader(),ck.getInterfaces(), (InvocationHandler) this);
   }


   private  void before(){
       System.out.println("开始找房");
   }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object o=method.invoke(this.target,args);
        after();
        return o;
    }

    private  void after(){
        System.out.println("入住");
    }
}
